﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization; 
using System.Security.Principal;
using System.Xml;
using Inaction.Core;
using System.ComponentModel;
using Inaction.Mapping;
using Inaction.Security;

namespace Inaction.Extensions.Security
{
    [DisplayName("用户")]
    [Table("UserInfo")]
    [Serializable]
    public class UserIdentity : Inaction.Security.IIdentity
    {
        #region 属性
        Guid? _id;
        public Guid? Id
        {
            get { return _id; }
            set { _id = value; }
        }

        String _name;
        public String Name
        {
            get { return _name; }
            set { _name = value; }
        }

        String _userNumber;
        public String UserNumber
        {
            get { return _userNumber; }
            set { _userNumber = value; }
        }

        UserType? _userType;
        public UserType? Type
        {
            get { return _userType; }
            set { _userType = value; }
        }

        Guid? departmentId;
        public Guid? DepartmentId
        {
            get { return departmentId; }
            set { departmentId = value; }
        }

        #endregion

        public UserIdentity() { }

        public UserIdentity(string number, string password)
        {
            UserNumber = number;
            Token = DEncrypt.MakeHashSalt(password);
        }

        #region 属性
        public byte[] Token { get; internal set; }
        public string AuthenticationType { get; set; }
        public bool IsAuthenticated { get; internal set; }
        public bool IsAdmin
        {
            get { return this.Type == UserType.Admin; }
        }
        #endregion
    }
}
